package com.hzhr.iot.user.dao;

import com.hzhr.iot.user.dao.mapper.custom.ResourceEntityCustomMapper;
import com.hzhr.iot.user.dao.mapper.generator.ResourceEntityMapper;
import com.hzhr.iot.user.entity.ResourceEntity;
import com.hzhr.iot.user.entity.ext.ResourceEntityExt;
import com.hzhr.iot.user.queryModel.custom.ResourceCustomQueryModel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.ArrayList;
import java.util.List;

@Repository
public class ResourceDao {
    @Autowired
    ResourceEntityMapper resourceEntityMapper;
    @Autowired
    ResourceEntityCustomMapper resourceEntityCustomMapper;

    public int insert(ResourceEntity record) {
        if (record == null) return 0;
        int changeCount = resourceEntityMapper.insert(record);
        return changeCount;
    }

    public int delete(ResourceCustomQueryModel queryModel) {
        if (queryModel == null) return 0;
        int changeCount = resourceEntityCustomMapper.delete(queryModel);
        return changeCount;
    }

    public int update(ResourceEntity record) {
        if (record == null) return 0;
        int changeCount = resourceEntityMapper.updateByPrimaryKey(record);
        return changeCount;
    }

    public int updateProps(ResourceCustomQueryModel queryModel) {
        if (queryModel == null) return 0;
        int changeCount = resourceEntityCustomMapper.updateProps(queryModel);
        return changeCount;
    }

    public ResourceEntity selectEntity(ResourceCustomQueryModel queryModel) {
        if (queryModel == null) return null;
        List<ResourceEntityExt> extList = resourceEntityCustomMapper.selectExt(queryModel);
        if (extList == null || extList.size() == 0) return null;
        return extList.get(0);
    }
    public List<ResourceEntity> selectEntityList(ResourceCustomQueryModel queryModel) {
        if (queryModel == null) return null;
        List<ResourceEntityExt> extList = resourceEntityCustomMapper.selectExt(queryModel);
        if (extList == null) return null;
        List<ResourceEntity> entityList = new ArrayList<>();
        for (ResourceEntityExt ext : extList) {
            entityList.add(ext);
        }
        return entityList;
    }
    public ResourceEntityExt selectExt(ResourceCustomQueryModel queryModel) {
        if (queryModel == null) return null;
        List<ResourceEntityExt> extList = resourceEntityCustomMapper.selectExt(queryModel);
        if (extList == null || extList.size() == 0) return null;
        return extList.get(0);
    }
    public List<ResourceEntityExt> selectExtList(ResourceCustomQueryModel queryModel) {
        if (queryModel == null) return null;
        List<ResourceEntityExt> extList = resourceEntityCustomMapper.selectExt(queryModel);
        return extList;
    }

    public ResourceEntity selectEntity1(ResourceCustomQueryModel queryModel) {
        if (queryModel == null) return null;
        List<ResourceEntityExt> extList = resourceEntityCustomMapper.selectExt1(queryModel);
        if (extList == null || extList.size() == 0) return null;
        return extList.get(0);
    }
    public List<ResourceEntity> selectEntityList1(ResourceCustomQueryModel queryModel) {
        if (queryModel == null) return null;
        List<ResourceEntityExt> extList = resourceEntityCustomMapper.selectExt1(queryModel);
        if (extList == null) return null;
        List<ResourceEntity> entityList = new ArrayList<>();
        for (ResourceEntityExt ext : extList) {
            entityList.add(ext);
        }
        return entityList;
    }
    public ResourceEntityExt selectExt1(ResourceCustomQueryModel queryModel) {
        if (queryModel == null) return null;
        List<ResourceEntityExt> extList = resourceEntityCustomMapper.selectExt1(queryModel);
        if (extList == null || extList.size() == 0) return null;
        return extList.get(0);
    }
    public List<ResourceEntityExt> selectExtList1(ResourceCustomQueryModel queryModel) {
        if (queryModel == null) return null;
        List<ResourceEntityExt> extList = resourceEntityCustomMapper.selectExt1(queryModel);
        return extList;
    }

    public int selectCount(ResourceCustomQueryModel queryModel) {
        if (queryModel == null) return 0;
        int count = resourceEntityCustomMapper.selectCount(queryModel);
        return count;
    }
    public int selectCount1(ResourceCustomQueryModel queryModel) {
        if (queryModel == null) return 0;
        int count = resourceEntityCustomMapper.selectCount1(queryModel);
        return count;
    }
    public int selectCount2(ResourceCustomQueryModel queryModel) {
        if (queryModel == null) return 0;
        int count = resourceEntityCustomMapper.selectCount2(queryModel);
        return count;
    }
}
